﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace SimpleNoteLib.Extensions
{
    internal static class DateTimeExtensions
    {
        internal static DateTime? FromUnixTimeInString(string unixTimeString)
        {
            if (string.IsNullOrWhiteSpace(unixTimeString))
            {
                return null;
            }
            double unixTime = double.Parse(unixTimeString, new CultureInfo("en-US"));
            return new DateTime(1970, 1, 1).AddSeconds(unixTime);
        }

        public static string ToUnixTimeString(this DateTime date)
        {
            TimeSpan diff = date - new DateTime(1970, 1, 1);
            return diff.TotalSeconds.ToString();
        }
    }
}
